using System.Data.SqlTypes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy3DRollLauncher : EnemyBaseFixed
{
    private Vector2[] rollsTargetPosition;
    private Vector2[] rollsPosition;
    void Awake()
    {
        base.Init();
        int rollCount=6;
        rollsTargetPosition=new Vector2[rollCount];
        for(int i=0;i<rollCount;i++){
            rollsTargetPosition[i]= new Vector2(80f+(i*24f),48f)/16f;
        }

        rollsPosition=new Vector2[rollsTargetPosition.Length];
        for(int i=0;i<rollsTargetPosition.Length;i++){
            rollsPosition[i]=camera3DLevel.TransformPlayerViewToEnemyView(rollsTargetPosition[i]);
        }

    }

    void FixedUpdate()
    {
        base.CommonFixedUpdate();
    }

    protected void UpdateStateNone(bool stateChanged, EnumState inState, out EnumState outState)
    {
        outState = EnumState.Working;

    }
    protected void UpdateStateWorking(bool stateChanged, EnumState inState, out EnumState outState)
    {
        outState = inState;
        fireAction.Update((SeqAction seq)=>{
            if(seq.IsFirstAction()){
                seq.PropertyInteger.Add("lastNo",-1);
            }
            int lastNo=seq.PropertyInteger["lastNo"];
            int no=Mathf.FloorToInt(seq.DurationTime/7.5f)+1;
            if(no!=lastNo){
                for(int i=0;i<rollsPosition.Length;i++){
                    GenRollerAtPosition(rollsPosition[i]);
                }
                seq.PropertyInteger["lastNo"]=no;
            }
        });
    }
    protected override void UpdateStateDie(bool stateChanged, EnumState inState, out EnumState outState)
    {
        outState = inState;
        Destroy(gameObject);

    }

    private void GenRollerAtPosition(Vector2 position){
        if(Instantiate(Constant.Prefabs.Enemy3DRoller.Load(),position,Quaternion.identity).TryGetComponent(out Enemy3DRoller roller)){
            roller.Run();
        }
    }

}
